package cn.xscrum.vtsp.controller;

import java.util.Date;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.xscrum.common.annotation.Log;
import cn.xscrum.common.enums.BusinessType;
import cn.xscrum.vtsp.domain.VtspFeedback;
import cn.xscrum.vtsp.service.IVtspFeedbackService;
import cn.xscrum.common.core.controller.BaseController;
import cn.xscrum.common.core.domain.AjaxResult;
import cn.xscrum.common.utils.poi.ExcelUtil;
import cn.xscrum.common.core.page.TableDataInfo;

/**
 * 问题反馈记录Controller
 * 
 * @author Zxing
 * @date 2021-10-01
 */
@Controller
@RequestMapping("/vtsp/feedback")
public class VtspFeedbackController extends BaseController {
    //静态资源前缀
    private String prefix = "vtsp/feedback";

    //Service层对象
    @Autowired
    private IVtspFeedbackService vtspFeedbackService;

    /**
     * 返回静态资源templates中的"/vtsp/feedback/feedback"视图
     */
    @RequiresPermissions("vtsp:feedback:view")
    @GetMapping()
    public String feedback() {
        return prefix + "/feedback";
    }

    /**
	 * 查询问题反馈记录列表
     */
    @RequiresPermissions("vtsp:feedback:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(VtspFeedback vtspFeedback) {
        startPage();
        if(vtspFeedback.getEndDate() != null) {
            //  Date -> 时间戳
            long timeStamp = vtspFeedback.getEndDate().getTime();
            //  时间戳 + (一天的秒数 - 1) * 1000
            timeStamp += (24 * 60 * 60 - 1) * 1000;
            //  时间戳 -> Date
            vtspFeedback.setEndDate(new Date(timeStamp));
        }
        //  根据vtspAdvice对象的属性查询
        List<VtspFeedback> list = vtspFeedbackService.selectVtspFeedbackList(vtspFeedback);
        return getDataTable(list);
    }

    /**
	 * 修改问题反馈记录
     */
    @GetMapping("/edit/{feedbackId}")
    public String edit(@PathVariable("feedbackId") Long feedbackId, ModelMap mmap) {
        VtspFeedback vtspFeedback = vtspFeedbackService.selectVtspFeedbackById(feedbackId);
        mmap.put("vtspFeedback", vtspFeedback);
        return prefix + "/edit";
    }

    /**
	 * 修改保存问题反馈记录
     */
    @RequiresPermissions("vtsp:feedback:edit")
    @Log(title = "问题反馈记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(VtspFeedback vtspFeedback) {
        return toAjax(vtspFeedbackService.updateVtspFeedback(vtspFeedback));
    }










    //未用到的方法------------------------------------------------------------------------------------------------------
    /**
	 * 删除问题反馈记录
     */
    @RequiresPermissions("vtsp:feedback:remove")
    @Log(title = "问题反馈记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(vtspFeedbackService.deleteVtspFeedbackByIds(ids));
    }


    /**
     * 导出问题反馈记录列表
     */
    @RequiresPermissions("vtsp:feedback:export")
    @Log(title = "问题反馈记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(VtspFeedback vtspFeedback)
    {
        List<VtspFeedback> list = vtspFeedbackService.selectVtspFeedbackList(vtspFeedback);
        ExcelUtil<VtspFeedback> util = new ExcelUtil<VtspFeedback>(VtspFeedback.class);
        return util.exportExcel(list, "feedback");
    }

    /**
     * 新增问题反馈记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存问题反馈记录
     */
    @RequiresPermissions("vtsp:feedback:add")
    @Log(title = "问题反馈记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(VtspFeedback vtspFeedback)
    {
        return toAjax(vtspFeedbackService.insertVtspFeedback(vtspFeedback));
    }
}
